package com.lib.framework.widget.dialog

import android.content.Context
import android.view.Gravity
import android.view.View
import androidx.databinding.DataBindingUtil
import com.lib.framework.R
import com.lib.framework.databinding.WidgetBottomCustomViewDialogBinding


/**
 * 底部自定义view对话框
 *
 * @author zhujun
 */
class BottomCustomViewDialog(context: Context, customView: View) : BaseDialog(context, R.style.defaultDialogTheme04) {

    private var mDataBinding: WidgetBottomCustomViewDialogBinding? = null

    private var mCustomView: View? = null

    init {
        mCustomView = customView
        initView()
        window?.let {
            it.setGravity(Gravity.BOTTOM) // 此处可以设置dialog显示的位置
            it.setWindowAnimations(R.style.BottomInAndOutStyle) // 添加动画

            // 设置 宽度充满整个屏幕
            val display = it.windowManager.defaultDisplay
            it.attributes.width = display.width //设置dialog的宽度为当前手机屏幕的宽度
        }

    }

    /**
     * 初始化视图
     */
    private fun initView() {
        mDataBinding = DataBindingUtil.inflate(layoutInflater, R.layout.widget_bottom_custom_view_dialog, null, false)
        mDataBinding?.let { dataBinding ->
            setContentView(dataBinding.root)
            fillView()
        }
    }

    /**
     * 填充视图
     */
    private fun fillView() {
        mDataBinding?.let { dataBinding ->
            dataBinding.llCustomViewContainer.removeAllViews()
            dataBinding.llCustomViewContainer.addView(mCustomView)
        }
    }

    /**
     * 设置底部按钮的点击监听器
     */
    fun setBottomBtnOnClickListener(l: View.OnClickListener) {
        mDataBinding?.tvBottomBtn?.setOnClickListener(l)
    }
}